package lhdx4;

public class Gongsi {
    String gongs;
    String zhuce;
    String dianHua;
    String jinYin;
    int k=0;
    Yuangong[] a=new Yuangong[45];
    public boolean add(String mame,int nianL,String xingB,String zhiW,int xinShui){
        if (k>=a.length){
            System.out.println("人已满！");
            return false;
        }
        a[k]=new Yuangong();
        a[k].mame=mame;
        a[k].nianL=nianL;
        a[k].xingB=xingB;
        a[k].zhiW=zhiW;
        a[k].xinShui=xinShui;
        k++;
        return true;
    }
    public void showInformation(){
        System.out.println("公司员工信息如下：");
        for (int i=0;i<k;i++){
            System.out.println(a[i].mame+"  "+a[i].nianL+"岁  "+a[i].xingB+" "+a[i].zhiW+" "+a[i].xinShui);
        }
    }
    public void ciTuei(String name){
        for (int i=0;i<k;i++){
            if (a[i].mame.equals(name)){
                for (int j=i;j<k-1;j++){
                    a[j].mame=a[j+1].mame;
                    a[j].nianL=a[j+1].nianL;
                    a[j].xingB=a[j+1].xingB;
                    a[j].zhiW=a[j+1].zhiW;
                    a[j].xinShui=a[j+1].xinShui;
                }
                a[k-1].mame=null;
                a[k-1].nianL=0;
                a[k-1].xingB=null;
                a[k-1].zhiW=null;
                a[k-1].xinShui=0;
                k--;
                System.out.println("已辞退！");
                return;
            }
        }
        System.out.println("未找到！");
    }
    public void tongJi(){
        System.out.println("公司人数:"+k+"人");
    }
    public void findTopSalary(){
        int c=a[0].xinShui;
        int b=0;
        for (int i=0;i<k;i++){
            if (a[i].xinShui>=c){
                c=a[i].xinShui;
                b=i;
            }
        }
        String A=a[b].mame;
        System.out.println("薪水最高的员工是："+A);

    }
    public void sortBySalDesc(){
        int b=0;
        String b1=null;
        String b2=null;
        String b3=null;
        int b4=0;
        for (int i=0;i<k;i++){
            for (int j=0;j<k-i-1;j++){
                if (a[j].xinShui<a[j+1].xinShui){
                    b=a[j].xinShui;
                    b1=a[j].mame;
                    b2=a[j].xingB;
                    b3=a[j].zhiW;
                    b4=a[j].nianL;
                    a[j].xinShui=a[j+1].xinShui;
                    a[j].mame=a[j+1].mame;
                    a[j].xingB=a[j+1].xingB;
                    a[j].zhiW=a[j+1].zhiW;
                    a[j].nianL=a[j+1].nianL;
                    a[j+1].xinShui=b;
                    a[j+1].mame=b1;
                    a[j+1].xingB=b2;
                    a[j+1].zhiW=b3;
                    a[j+1].nianL=b4;

                }
            }
        }
        System.out.print("排序 ");
        for (int i=0;i<k;i++){
            System.out.print(a[i].xinShui + "  ");
        }
    }

}
